package com.fr.data;

import com.fr.base.FRContext;
import com.fr.base.ReflectionUtils;
import com.fr.base.StringUtils;
import com.fr.base.core.FRCoreContext;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.script.Calculator;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ClassSubmitJob
  implements SubmitJob
{
  private String className;
  private Map propertyMap = new HashMap();

  public ClassSubmitJob()
  {
  }

  public ClassSubmitJob(String paramString)
  {
    setClassName(paramString);
  }

  public String getClassName()
  {
    return this.className;
  }

  public void setClassName(String paramString)
  {
    this.className = paramString;
  }

  public void setPropertyMap(Map paramMap)
  {
    this.propertyMap = paramMap;
  }

  public Map getPropertyMap()
  {
    return this.propertyMap;
  }

  public void doJob(Calculator paramCalculator)
    throws Exception
  {
    Field[] arrayOfField;
    int i;
    if (StringUtils.isBlank(getClassName()))
      return;
    Object localObject = null;
    try
    {
      Class localClass = FRCoreContext.classForName(getClassName());
      localObject = localClass.newInstance();
      arrayOfField = localClass.getDeclaredFields();
      for (i = 0; i < arrayOfField.length; ++i)
      {
        String str = arrayOfField[i].getName();
        if (getPropertyMap().containsKey(str))
          ReflectionUtils.setPrivateFieldValue(localObject, str, getPropertyMap().get(str));
      }
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
    if (!(localObject instanceof SubmitJob))
      return;
    ((SubmitJob)localObject).doJob(paramCalculator);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
      getPropertyMap().clear();
    if (paramXMLableReader.isChildNode())
      if (paramXMLableReader.getTagName().equals("ClassAttr"))
      {
        String str1;
        if (StringUtils.isNotBlank(str1 = paramXMLableReader.getAttr("className")))
          setClassName(str1);
      }
      else if ("Property".equals(paramXMLableReader.getTagName()))
      {
        String str2 = paramXMLableReader.getAttr("name");
        if (StringUtils.isNotBlank(str2))
          paramXMLableReader.readXMLObject(new XMLReadable(this, str2)
          {
            private final String val$name;
            private final ClassSubmitJob this$0;

            public void readXML()
            {
              if ((paramXMLableReader.isChildNode()) && ("O".equals(paramXMLableReader.getTagName())))
                this.this$0.getPropertyMap().put(this.val$name, ReportXMLUtils.readObject(paramXMLableReader));
            }
          });
      }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (StringUtils.isNotBlank(getClassName()))
      paramXMLPrintWriter.startTAG("ClassAttr").attr("className", getClassName()).end();
    Iterator localIterator = getPropertyMap().entrySet().iterator();
    while (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      String str = (String)localEntry.getKey();
      Object localObject = localEntry.getValue();
      paramXMLPrintWriter.startTAG("Property").attr("name", str);
      ReportXMLUtils.writeObject(paramXMLPrintWriter, localObject);
      paramXMLPrintWriter.end();
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}